package com.example.picturebrowser;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

    private RelativeLayout relativeLayout;
    private RadioGroup radioGroup;
    private ImageView imageView;
    private Button button1;
    private Button button2;
    private int[] imArray;
    private int index=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        relativeLayout=this.findViewById(R.id.relativeLayout);
        radioGroup=this.findViewById(R.id.radioGroup);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId==R.id.radioButton1){
                    relativeLayout.setBackgroundResource(R.drawable.simg);
                }
                if (checkedId==R.id.radioButton2){
                    relativeLayout.setBackgroundResource(R.drawable.timg);
                }
            }
        });

        imageView=this.findViewById(R.id.imageView);
        button1=this.findViewById(R.id.button1);
        button2=this.findViewById(R.id.button2);
        imArray=new int[]{R.drawable.picture0,R.drawable.picture1,R.drawable.picture2,
                R.drawable.picture3, R.drawable.picture4, R.drawable.picture5,
                R.drawable.picture6,R.drawable.picture7, R.drawable.picture8,
                R.drawable.picture9, R.drawable.picture10,R.drawable.picture11,R.drawable.picture12};
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                previousPic();
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                nextPic();
            }
        });
    }

    private void nextPic(){
        index++;
        imageView.setImageResource(imArray[index%13]);
    }

    private void previousPic(){

        if (index>=1){
            index--;
            imageView.setImageResource(imArray[index%13]);
        }
    }
}
